import { BaseWindow } from "../../../component/window/BaseWindow";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { TilePanel } from "../equipment/TilePanel";
import { FriendRequestRenderer } from "./FriendRequestRenderer";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ReplyType } from "./defin/ReplyType";
import { GButton } from "../../../../com/mui/controls/GButton";
import { OK } from "../../../../ReplyType/OK";
import { CANCEL } from "../../../../ReplyType/CANCEL";
type int = number;
//class FriendRequestWindow
    
    export  class FriendRequestWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this.setSize(325, 155);
            this.titleHeight = 28;
            this.title = Language.getString(40359);
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._bg = ObjCreate.createBg(17, 39, 290, 80, this);
            this._requestList = new TilePanel();
            this._requestList.horizontalGap = 3;
            this._requestList.verticalGap = 3;
            this._requestList.columnWidth = 260;
            this._requestList.rowHeight = 60;
            this._requestList.setSize(260, 60);
            this._requestList.move(40, 50);
            this._requestList.setStyle("cellRenderer", FriendRequestRenderer);
            this.addChild(this._requestList);
            this._agreeBtn = ObjCreate.createGButton(Language.getString(40360), 220, 120, 70, 24, this);
            this._agreeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onAgreeBtnClickHandler);
            this._ignoreBtn = ObjCreate.createGButton(Language.getString(40361), 50, 120, 70, 24, this);
            this._ignoreBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onIgnoreBtnClickHandler);
            return;
        }

        public updateDataProvider(arg1: Array<any>): void
        {
            var loc2=null;
            this._dataArray = [];
            this.resetWindow(arg1.length);
            var loc1=new DataProvider();
            var loc3=0;
            while (loc3 < arg1.length) 
            {
                loc2 = arg1[loc3] as Object;
                this._dataArray.push(loc2);
                loc1.addItem(loc2);
                ++loc3;
            }
            this._requestList.dataProvider = loc1;
            return;
        }

        /* internal  */resetWindow(arg1: int): void
        {
            if (arg1 <= 4) 
            {
                this.height = 155 + (arg1 - 1) * 60;
                this._bg.height = 80 + (arg1 - 1) * 60;
                this._requestList.setSize(250, 60 + (arg1 - 1) * 60);
                this._ignoreBtn.y = 120 + (arg1 - 1) * 60;
                this._agreeBtn.y = 120 + (arg1 - 1) * 60;
            }
            else 
            {
                this.height = 155 + (4 - 1) * 60;
                this._bg.height = 80 + (4 - 1) * 60;
                this._requestList.setSize(250, 60 + (4 - 1) * 60);
                this._ignoreBtn.y = 120 + (4 - 1) * 60;
                this._agreeBtn.y = 120 + (4 - 1) * 60;
            }
            return;
        }

        /* internal  */onAgreeBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.FriendReplyAdd, {"playerId": 0, "type": OK, "applyList": this._requestList.dataProvider.toArray()}));
            return;
        }

        /* internal  */onIgnoreBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.FriendReplyAdd, {"playerId": 0, "type": CANCEL}));
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this.updateDataProvider([]);
            return;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_requestList: TilePanel;

        /* internal */ /* var */_agreeBtn: GButton;

        /* internal */ /* var */_ignoreBtn: GButton;

        /* internal */ /* var */_dataArray: Array<any>;
    }
